# renderer/Makefile
# Dynamical
# Matthew Jee
# mcjee@ucsc.edu

NEEDS_DEPENDENCIES = ${filter clean,${MAKECMDGOALS}}

BUILD_PRODUCT   = mjrender.a

C_SOURCE        = matrix.cpp camera.cpp shader.cpp mesh.cpp renderable.cpp \
                  scene.cpp framebuffer.cpp texture.cpp transform.cpp
OBJECTS         = $(C_SOURCE:%.cpp=%.o)

UNAME           = $(shell uname -s)

ifeq "$(UNAME)" "Darwin"
COMPILER        = clang++
endif

ifeq "$(UNAME)" "Linux"
COMPILER        = g++
endif

COMPILE_OPTIONS = -Wall -Wextra -pedantic

COMPILE_CMD     = $(COMPILER) $(COMPILE_OPTIONS)

all: $(BUILD_PRODUCT)

$(BUILD_PRODUCT): $(OBJECTS)
	@echo Archiving Library ===================================================
	ar -rs $(BUILD_PRODUCT) $(OBJECTS)

%.o: %.cpp
	$(COMPILE_CMD) -o $@ -c $<

clean:
	@echo Cleaning Renderer ===================================================
	- rm $(OBJECTS) $(BUILD_PRODUCT) dependencies

dependencies:
	$(COMPILER) -MM $(C_SOURCE) > dependencies

ifeq "$(NEEDS_DEPENDENCIES)" ""
include dependencies
endif
